package com.paas.form.controller;


import com.bpm.feign.model.ProcessCmd;
import com.paas.common.model.BaseUserInfo;
import com.paas.common.model.RestResponse;
import com.paas.common.util.BeanUtil;
import com.paas.common.util.StringUtil;
import com.paas.common.util.UniqueIdUtil;
import com.paas.common.web.annotion.OperLog;
import com.paas.common.web.controller.BaseController;
import com.paas.common.web.oper.OprLogConstant;
import com.paas.form.dto.FormInfoChangeDto;
import com.paas.form.dto.FormViewPubChangeDto;
import com.paas.form.service.IFormChangeService;
import com.paas.form.service.IViewChangeService;
import com.paas.form.vo.FormViewPubChangeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@RestController
@RequestMapping(value = "/form/viewChange")
@Api(description = "视图模块", tags = "")
public class ViewChangeController extends BaseController {

    @Autowired
    private IViewChangeService viewChangeService;



    @RequestMapping(value = "/saveViewPubChangeInfo",method = RequestMethod.POST)
    @ApiOperation(value = "保存变更信息", notes = "保存变更信息")
    @OperLog(operType = OprLogConstant.ADD,operModul = "",operDescribe = "-保存")
    public RestResponse saveViewPubChangeInfo(@RequestBody FormViewPubChangeVo<ProcessCmd> formViewPubChangeVo) throws ParseException{
            BaseUserInfo baseUserInfo = getUserInfo();
            FormViewPubChangeDto formViewPubChangeDto = formViewPubChangeVo.getFormViewPubChangeDto();
            if (BeanUtil.isNotEmpty(formViewPubChangeDto)){
                ProcessCmd processCmd = formViewPubChangeVo.getProcessCmd();
                return  viewChangeService.saveViewPubChangeInfo(formViewPubChangeDto,processCmd,baseUserInfo);
            }
            return RestResponse.error();

    }


    @RequestMapping(value = "/getFormChangeDetail",method = RequestMethod.GET)
    @ApiOperation(value = "查询变更明细", notes = "查询变更明细")
    public FormViewPubChangeDto getFormChangeDetail(String logId) throws ParseException {
        FormViewPubChangeDto formInfoChangeDto = new FormViewPubChangeDto();
        if (StringUtil.isNotEmpty(logId)){
            formInfoChangeDto =  viewChangeService.getViewPubChangeDtoById(logId);
        }
        return formInfoChangeDto;
    }

    @RequestMapping(value = "/approvalViewChange",method = RequestMethod.POST)
    @ApiOperation(value = "同意变更", notes = "同意变更")
    public RestResponse approvalViewChange(String bussinessKey) throws ParseException {
        if (StringUtil.isNotEmpty(bussinessKey)){
            return viewChangeService.approvalViewChange(bussinessKey);
        }
        return RestResponse.error();
    }


    @RequestMapping(value = "/opposeViewChange",method = RequestMethod.POST)
    @ApiOperation(value = "反对变更", notes = "反对变更")
    public RestResponse opposeViewChange(String bussinessKey) throws ParseException {
        if (StringUtil.isNotEmpty(bussinessKey)){
            return viewChangeService.opposeViewChange(bussinessKey);
        }
        return RestResponse.error();
    }
}